package com.api.workflow.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Cell;
import weaver.soa.workflow.request.DetailTable;
import weaver.soa.workflow.request.RequestInfo;
import weaver.soa.workflow.request.Row;

/**
 * @author wanghan
 * @version 1.0
 * @Description 应付账款解冻
 * @since 2025/2/27 12:29
 */
public class UnfreezingAccountsPayableAction extends BaseBean implements Action{
    private String hth;

    public String getHth() {
        return hth;
    }

    public void setHth(String hth) {
        this.hth = hth;
    }

    @Override
    public String execute(RequestInfo requestInfo) {
        try {

            //获得流程id
            String workflowid = requestInfo.getWorkflowid();
            //获取表id
            String requestid = requestInfo.getRequestid();
            writeLog("UnfreezingAccountsPayableAction-----start----------------------" + requestid);
            writeLog("hthhthhth"+this.hth);
            RecordSet rs = new RecordSet();
            rs.execute("select tablename from workflow_base a,workflow_bill b where a.formid=b.id and a.id=" + workflowid);
            rs.next();
            //获取主表名
            String maintable = Util.null2String(rs.getString("tablename"));
            writeLog("maintablemaintablemaintable" + maintable);
            DetailTable[] detailTable = requestInfo.getDetailTableInfo().getDetailTable();
            writeLog("detailTabledetailTable" + detailTable);
            JSONArray arrayListmx1 = new JSONArray();
            DetailTable detailTablemx1=detailTable[0];
            Row[] rowmx1 = detailTablemx1.getRow();
            if (rowmx1.length>0){
                for (Row r:rowmx1){//遍历明细1
                    JSONObject jsonObject = new JSONObject();
                    Cell[] cell = r.getCell();
                    for (Cell c1:cell){
                        jsonObject.put(c1.getName(),c1.getValue());
                    }
                    arrayListmx1.add(jsonObject);

                }
            }
            writeLog("arrayListmx1" + arrayListmx1);
            if (arrayListmx1.size()>0){
                for (int i=0;i<arrayListmx1.size();i++){
                    String sql="";
                    String hth = String.valueOf(arrayListmx1.getJSONObject(i).get(this.hth));//获取应付账款唯一标识
                    sql="update uf_yfzkbd set ycbs=0 where wybs=?";
                    rs.executeUpdate(sql,hth);
                }
            }
            return Action.SUCCESS;

        }catch (Exception e){
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("接口出错,请联系管理员!"+e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
